/**
 * 
 */
package com.htht.tourism.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.htht.tourism.domain.Activity_sign;
import com.htht.tourism.domain.Response;
import com.htht.tourism.domain.link.ActivityParam;
import com.htht.tourism.domain.link.Activity_signParam;
import com.htht.tourism.intf.ActivitySignService;
import com.htht.tourism.utils.ValidatorResultHandler;

/**
 * @author wuqiwei
 *
 */
@Controller
@ResponseBody
@RequestMapping("/activitySign")
public class ActivitySignController {
	@Resource
	private ActivitySignService activitySignService;
	
	/**
	 * 取消报名
	 * @author:wuqiwei
	 * @param @param param
	 * @param @param result
	 * @param @return
	 * @date:2017年3月16日下午3:31:31
	 */
	@RequestMapping(value = "/cancel", method = RequestMethod.POST)
	public Response cancel(@RequestBody @Validated Activity_signParam param,
			BindingResult result) {
		Response retVal = ValidatorResultHandler.handle(result);
		if (retVal == null) {
			int a = this.activitySignService.cancel(param);
			if (a > 0) {
				return Response.getInstance().success(a);
			} else {
				return Response.getInstance().failure("取消失败！");
			}
		} else {
			return retVal;
		}
	}
	
	/**
	 * 查询是否报名
	 * @author:wuqiwei
	 * @param @param param
	 * @param @param result
	 * @param @return
	 * @date:2017年3月16日下午4:40:23
	 */
	@RequestMapping(value = "/get", method = RequestMethod.POST)
	public Response get(@RequestBody @Validated Activity_signParam param,
			BindingResult result) {
		Response retVal = ValidatorResultHandler.handle(result);
		if (retVal == null) {
			List<Activity_sign> list = this.activitySignService.get(param);
			if (list.size() > 0) {
				return Response.getInstance().success(list);
			} else {
				return Response.getInstance().failure("查询失败！");
			}
		} else {
			return retVal;
		}
	}
	/**
	 * 活动报名（判断当前活动人数是否已经报满）
	 * @author:wuqiwei
	 * @param @param param
	 * @param @param result
	 * @param @return
	 * @date:2017年3月17日上午9:32:33
	 */
	@RequestMapping(value = "/sign", method = RequestMethod.POST)
	public Response sign(@RequestBody @Validated Activity_signParam param,
			BindingResult result) {
		Response retVal = ValidatorResultHandler.handle(result);
		if (retVal == null) {
			int a = this.activitySignService.sign(param);
			if (a > 0) {
				return Response.getInstance().success(a);
			} else {
				return Response.getInstance().failure("报名失败！");
			}
		} else {
			return retVal;
		}
	}
	/**
	 * 评价活动（评价条件：活动已结束、已参加该活动）
	 * @author:wuqiwei
	 * @param @param param
	 * @param @param result
	 * @param @return
	 * @date:2017年3月17日上午11:06:24
	 */
	@RequestMapping(value = "/remarkon", method = RequestMethod.POST)
	public Response remarkon(@RequestBody @Validated Activity_signParam param,
			BindingResult result) {
		Response retVal = ValidatorResultHandler.handle(result);
		if (retVal == null) {
			int a = this.activitySignService.remarkon(param);
			if (a > 0) {
				return Response.getInstance().success(a);
			} else {
				return Response.getInstance().failure("评价失败！");
			}
		} else {
			return retVal;
		}
	}
	
	/**
	 * 根据活动id查询参加活动人数
	 * @author:wuqiwei
	 * @param @param param
	 * @param @param result
	 * @param @return
	 * @date:2017年3月30日下午2:35:19
	 */
	@RequestMapping(value = "/getSignNumber", method = RequestMethod.POST)
	public Response getSignNumber(@RequestBody @Validated Activity_signParam param,
			BindingResult result) {
		Response retVal = ValidatorResultHandler.handle(result);
		if (retVal == null) {
			int  a  = this.activitySignService.getSignNumber(param);
			if (a >= 0) {
				return Response.getInstance().success(a);
			} else {
				return Response.getInstance().failure("查询失败！");
			}
		} else {
			return retVal;
		}
	}
}
